<?php
class User_Model_Users extends Pldkp_Db_Table_Abstract
{
    protected $_name = 'users';
    protected $_rowClass = 'User_Model_UserRow';

    protected $_dependentTables = array(
        'User_Model_Signups',
        'User_Model_Characters',
        'User_Model_UsersGroups',
        'Raid_Model_Raids'
    );
    
    public static function getById($id)
    {
        // id must be numeric
        if (!is_numeric($id)) {
            return null;
        }
       
        
        // Create static self
        $table = new self();
        
        // Create a select for getting the raid
        $select = $table->select()->where('id = ?', $id);
        $row = $table->fetchRow($select);
        
        // Return the raid or null
        if ($row) {
            return $row;
        } else {
            return null;
        }
    }
    
    public static function getByHandle($handle)
    {
        // Create static self
        $table = new self();
        
        // Create a select for getting the raid
        $select = $table->select()->where("handle = ?", $handle);
        $user = $table->fetchRow($select);
        
        // Return the raid or null
        if ($user) {
            return $user;
        } else {
            return null;
        }
    }
    
    public static function getByEmail($email)
    {
        // Create static self
        $table = new self();
        
        // Create a select for getting the raid
        $select = $table->select()->where("email = ?", $email);
        $user = $table->fetchRow($select);
        
        // Return the raid or null
        if ($user) {
            return $user;
        } else {
            return null;
        }
    }
}
